package com.drought.rained.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.drought.rained.R;
import com.drought.rained.bean.ImgsListDataLJ;
import com.drought.rained.business.GlideImageLoaderLJ;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ImgListAdapterLJ extends RecyclerView.Adapter<ImgListAdapterLJ.ImgListViewHolder> {
    private OnItemClickListener onItemClickListener;
    private Context context;
    private List<ImgsListDataLJ.ImgPathListBean> data;

    public ImgListAdapterLJ(Context context, List<ImgsListDataLJ.ImgPathListBean> data) {
        this.context = context;
        this.data = data;
    }

    @NonNull
    @Override
    public ImgListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_img_list_layout, parent, false);
        return new ImgListViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final ImgListViewHolder holder, int position) {
        switch (position) {
            case 0:
                holder.tv.setText(context.getString(R.string.custom_auth_page_shuika));
                break;
            case 1:
                holder.tv.setText(context.getString(R.string.custom_auth_page_baoxiandan));
                break;
            case 2:
                holder.tv.setText(context.getString(R.string.custom_auth_page_hukouben));
//                holder.mark.setVisibility(View.VISIBLE);
                break;
            case 3:
                holder.tv.setText(context.getString(R.string.custom_auth_page_cunzhe));
                break;
            case 4:
                holder.tv.setText(context.getString(R.string.custom_auth_page_mingpain));
                break;
            case 5:
                holder.tv.setText(context.getString(R.string.custom_auth_page_jiashizheng));
                break;
            case 6:
                holder.tv.setText(context.getString(R.string.custom_auth_page_chepai));
                break;
            case 7:
                holder.tv.setText(context.getString(R.string.custom_auth_page_yongtupingzheng));
                break;
            case 8:
                holder.tv.setText(context.getString(R.string.custom_auth_page_xinyongka));
                break;
            case 9:
                holder.tv.setText(context.getString(R.string.custom_auth_page_gongzuozhengming));
                break;
        }


        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onClick(holder.itemView, holder.getLayoutPosition());
                }
            }
        });
        setVisiable(holder,position);

        if (null != data.get(position).getNativeFileUri()) {
            GlideImageLoaderLJ.LoadImage(context, data.get(position).getNativeFileUri(), holder.ivPhoto);
            return;
        }

        if (!TextUtils.isEmpty(data.get(position).getImagePathUrl())) {
            GlideImageLoaderLJ.LoadImage(context, data.get(position).getImagePathUrl(), holder.ivPhoto);
        }
    }


    private void setVisiable( ImgListViewHolder holder ,int position) {
        if(data.get(position).getNativeFileUri()==null&&TextUtils.isEmpty(data.get(position).getImagePathUrl())){
            holder.tv.setVisibility(View.VISIBLE);
        }else {
            holder.tv.setVisibility(View.INVISIBLE);
//            holder.mark.setVisibility(View.INVISIBLE);
        }

    }

    @Override
    public int getItemCount() {
        return data.size();
    }


    @Override
    public long getItemId(int position) {
        return position;
    }

    public class ImgListViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv)
        ImageView iv;
        @BindView(R.id.tv)
        TextView tv;
//        @BindView(R.id.mark)
//        TextView mark;
        @BindView(R.id.iv_photo)
        ImageView ivPhoto;

        public ImgListViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


    public interface OnItemClickListener {
        void onClick(View view, int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
}
